package samsung.sds.systemMonitor.SQLMonitor.controller;


import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import samsung.sds.system.common.baseQuery.model.PageData;
import samsung.sds.system.common.model.QueryParam;
import samsung.sds.system.utils.CommonTools;
import samsung.sds.systemMonitor.SQLMonitor.model.SQLMonitorEntity;
import samsung.sds.systemMonitor.SQLMonitor.service.SQLMonitorService;

/**
 * @author wei5.gao
 * @createDate 2016-02-22
 * 
 * SQL监控控制器
 */
@Controller
@RequestMapping("/systemMonitor/SQLMonitor")
public class SQLMonitorController {
	
	@Autowired
	private SQLMonitorService sQLMonitorServiceImpl;
	
	/**
	 * 跳转到SQL日志列表页面
	 * @param request
	 * @param modelMap
	 * @return
	 */
	@RequestMapping(value="/SQLMonitorList",method = RequestMethod.POST)
	public String SQLMonitorList(HttpServletRequest request, ModelMap modelMap){
		//返回当前页功能所用到的参数
		String pageType = request.getParameter("pageType");
		modelMap.addAttribute("pageType", pageType);
		modelMap.addAttribute("currentTime", CommonTools.getCurrentDateTime());
		return "/systemMonitor/SQLMonitor/SQLMonitorList";
	}
	
	/**
	 * 分页显示SQL日志信息
	 * @param request
	 * @return
	 */
	@RequestMapping(value="/getSQLMonitorList",method = RequestMethod.POST)
	@ResponseBody
	public PageData<SQLMonitorEntity> querySQLMonitor(HttpServletRequest request){
		QueryParam param = CommonTools.getQueryParam(request);
		return sQLMonitorServiceImpl.queryListPage(param);
	}
	
	/**
	 * 显示某条SQL日志详情信息
	 * @param request
	 * @param detailsId
	 * @param modelMap
	 * @return
	 */
	@RequestMapping(value="/SQLMonitorDetails",method = RequestMethod.POST)
	public String getListDetails(HttpServletRequest request,String detailsId,ModelMap modelMap){
		SQLMonitorEntity detailsEntity = sQLMonitorServiceImpl
				.findEntityById(detailsId);
		modelMap.put("entity", detailsEntity);
		return "/systemMonitor/SQLMonitor/SQLMonitorDetails";
	}

}
